package com.ssy.lingxi.pay.serviceimpl;

import cn.hutool.core.date.DateUtil;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.pay.entity.CreditOuterVerifyRecordDO;
import com.ssy.lingxi.pay.model.vo.response.CreditOuterVerifyRecordVO;
import com.ssy.lingxi.pay.repository.CreditOuterVerifyRecordRepository;
import com.ssy.lingxi.pay.service.ICreditOuterVerifyRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 授信外部审核记录接口实现
 * @author 伍将
 * @date 2020/8/18
 * @version 2.0.0
 */
@Service
public class CreditOuterVerifyRecordServiceImpl implements ICreditOuterVerifyRecordService {

    @Resource
    private CreditOuterVerifyRecordRepository recordRepository;

    /**
     * 获取审核历史记录
     * @author 伍将
     * @date 2020/8/20
     * @param applyId:
     * @return com.ssy.lingxi.common.response.Wrapper<java.util.List < com.ssy.lingxi.pay.model.vo.response.CreditOuterVerifyRecordVO>>
     **/
    @Override
    public Wrapper<List<CreditOuterVerifyRecordVO>> getHistoryList(Long applyId) {

        // step 1: 查询数据
        List<CreditOuterVerifyRecordDO> recordDOList = recordRepository.findByApplyIdOrderByOperateTimeAsc(applyId);

        // step 2: 组装返回数据
        List<CreditOuterVerifyRecordVO> resultList = recordDOList.stream().map(r -> {
            CreditOuterVerifyRecordVO queryVO = new CreditOuterVerifyRecordVO();
            queryVO.setRoleName(r.getRoleName());
            queryVO.setStatus(r.getStatus());
            queryVO.setOperate(r.getOperate());
            queryVO.setOperateTime(DateUtil.format(DateUtil.date(r.getOperateTime()), "yyyy-MM-dd HH:mm"));
            queryVO.setOpinion(r.getOpinion());

            return queryVO;
        }).collect(Collectors.toList());

        return Wrapper.success(resultList);

    }
}
